package com.cg.service.impl;

import com.cg.dao.DictionaryMapper;
import com.cg.dao.DictionaryTypeMapper;
import com.cg.dto.DictionaryDto;
import com.cg.dto.DictionaryPageDto;
import com.cg.entity.Dictionary;
import com.cg.entity.DictionaryType;
import com.cg.service.DictionaryTypeService;
import com.cg.vo.DictionaryVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (DictionaryType)表服务实现类
 *
 * @author chengong
 * @since 2023-12-01 10:25:11
 */
@Service("dictionaryTypeService")
public class DictionaryTypeServiceImpl implements DictionaryTypeService {
    @Resource
    private DictionaryTypeMapper dictionaryTypeMapper;

    @Resource
    private DictionaryMapper dictionaryMapper;

    /**
     * 查询全部Type
     * @return
     */
    @Override
    public List<DictionaryType> queryTypeAll() {
        return dictionaryTypeMapper.queryTypeAll();
    }


    /**
     * 新增
     */
    @Override
    public Integer createDictionaryType(DictionaryDto dictionaryDto) {
        Integer count = 0;
        Dictionary dictionary = new Dictionary();
        DictionaryType dictionaryType = new DictionaryType();

        BeanUtils.copyProperties(dictionaryDto,dictionary);
        BeanUtils.copyProperties(dictionaryDto,dictionaryType);
        dictionaryMapper.createDictionary(dictionary);
        count = dictionaryTypeMapper.createDictionaryType(dictionaryType);

        return count;
    }

    /**
     * 查询数据字典表
     */
    @Override
    public PageInfo<DictionaryVo> queryDictionary(DictionaryPageDto dictionaryPageDto) {
        PageHelper.startPage(dictionaryPageDto.getPageNum(),dictionaryPageDto.getPageSize());
        List<DictionaryVo> dictionaryVos = dictionaryTypeMapper.queryDictionary(dictionaryPageDto.getTypeName());
        PageInfo<DictionaryVo> pageInfo = new PageInfo<>(dictionaryVos);
        return pageInfo;
    }
}
